package vue.components;

import java.awt.Color;

import javax.swing.JTextPane;
import javax.swing.text.Document;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
/**
 * <p>Title: vue.components.TPTextPane </p>
 *
 * <p>
 * 	Description: Cette classe est notre composant JTextPane particulie 
 * </p>
 *
 * <p>Copyright: (c) 2008 FSSIM</p>
 *
 * <p>Company: FSSImock</p>
 *
 * @author Antoine Farnault
 * @version 1.0
 */
public class TPTextPane extends JTextPane {

	private static final long serialVersionUID = 1L;
	public Style parentStyle;
	public Document doc;
	
	/**
	 * Constructeur
	 */
	public TPTextPane() {
		parentStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
		doc = getDocument();
	}
	/**
	 * Ajoute un message a la fin du JTextPane
	 * @param msg
	 * @param color
	 * @param bgColor
	 * @param isBold
	 */
	public void append(String msg, Color color, Color bgColor, boolean isBold,boolean isItalic) {
		StyleConstants.setForeground(parentStyle, color);
		StyleConstants.setBackground(parentStyle, bgColor);
		StyleConstants.setBold(parentStyle, isBold);
		StyleConstants.setItalic(parentStyle, isItalic);
		StyleConstants.setFontFamily(parentStyle, "Monospaced");
		StyleConstants.setFontSize(parentStyle, getFont().getSize() +2 );
		int len = doc.getLength();
		try {
			doc.insertString(len, msg, parentStyle);
		} catch (Exception e) {
			e.printStackTrace();
			System.err.print("Failed to append msg ["+msg+"]" );
		}
	}
}
